{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# ART decision tree classifier attack"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This notebook shows how to compute adversarial examples on decision trees (as described in by Papernot et al. in https://arxiv.org/abs/1605.07277). Due to the structure of the decision tree, an adversarial example can be computed without any explicit gradients, only by traversing the learned tree structure.\n",
    "\n",
    "Consider the following simple decision tree for four dimensional data, where we go to the left if a condition is true:\n",
    "\n",
    "                    F1<3\n",
    "           \n",
    "              F2<5        F2>2\n",
    "                \n",
    "         F4>3     C1    F3<1     C3* \n",
    "             \n",
    "      C1     C2       C3    C1  \n",
    "      \n",
    "Given sample [4,4,1,1], the tree outputs C3 (as indicated by the star). To misclassify the sample, we walk one node up and explore the subtree on the left. We find the leaf outputting C1 and change the two features, obtaining [4,1.9,0.9,1]. In this implementation, we change only the features with wrong values, and specify the offset in advance."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Applying the attack"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "from sklearn.tree import DecisionTreeClassifier\n",
    "from sklearn.datasets import load_digits\n",
    "from matplotlib import pyplot as plt\n",
    "import numpy as np\n",
    "\n",
    "from art.attacks import DecisionTreeAttack\n",
    "from art.classifiers import SklearnClassifier"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[0 1 2 3 4 5 6 7 8 9 0 1 2 3]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<matplotlib.colorbar.Colorbar at 0x7f946c9fab00>"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAASQAAAD8CAYAAADe49kaAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RV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\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "digits = load_digits()\n",
    "X = digits.data\n",
    "y = digits.target\n",
    "\n",
    "clf = DecisionTreeClassifier()\n",
    "clf.fit(X,y)\n",
    "clf_art = SklearnClassifier(clf)\n",
    "print(clf.predict(X[:14]))\n",
    "plt.imshow(X[0].reshape(8,8))\n",
    "plt.colorbar()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We now craft adversarial examples and plot their classification. The difference is really small, and often only one or two features are changed."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5 4 4 6 5 4 1 2 4 4 5 4 6 4]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7f946cbc9908>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPgAAAD8CAYAAABaQGkdAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAACxRJREFUeJzt3X+o1fUdx/HXa1ftLjMd2Sq8Mv2jhLZYlnOIEUxp6IoKNkihxmJwYVAUyaJGY9v/Ee6PEYTVglzSrCBaPxaraIEzf+Ra/homDa9UGv0WUm++98c9goXb/V7P9/v5nvPu+YBL98fhft6HePr9nnPP+X4cEQKQ09faHgBAcwgcSIzAgcQIHEiMwIHECBxIjMCBxAgcSIzAgcQmNfFLp/i0GNTUJn51q0Znlr1P5577frG19h+aUWytwZGjxdaKo6PF1irpMx3SkTjs8W7XSOCDmqrve2kTv7pV7/14UdH1frl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GIuL4mdZ6jQXft3oh8E2Szrc9t/OkxgpJT7Y8U9dsW2OP5XZGxD1tz1OXiLgzIoYiYo7G/l+9EBHXtzxWLSLiHUn7bM/rfGuppL5+UnSie5PVLiJGbd8k6TlJA5IeiIjtLY9Vh8WSbpD0L9vbOt/7VUQ83eJMGN/NktZ2DjZ7Jd3Y8jxdaf3PZACa0wun6AAaQuBAYgQOJEbgQGIEDiRG4EBiBA4kRuBAYv8FczmfQj2ZpigAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "attack = DecisionTreeAttack(clf_art)\n",
    "adv = attack.generate(X[:14])\n",
    "print(clf.predict(adv))\n",
    "plt.imshow(adv[0].reshape(8,8))\n",
    "# plt.imshow((X[0]-adv[0]).reshape(8,8))  ##use this to plot the difference"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The change is possibly larger if we specify which class the sample should be (mis-)classified as. To do this, we just specify a label for each attack point."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[6 6 7 7 8 8 9 9 1 1 2 2 3 3]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<matplotlib.image.AxesImage at 0x7f946cb30160>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAPgAAAD8CAYAAABaQGkdAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDMuMC4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvOIA7rQAACxZJREFUeJzt3X2olvUdx/HPJx9ymdORLcMjU6KE9pQlDjGCKQ1dUcEGKVQsBg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g5LWifpypZn6llEvBURWzoffyRpp6TZ7U5VD9tDki6TtKbtWepke7qkSyTdJ0kRcXiQ45b6I/DZkvYe9/mIkoRwjO25khZI2tjuJLW5W9Ktko62PUjN5kk6IOmBzo8fazr3IxxY/RB4arZPl/SopJsj4sO25+mV7csl7Y+IzW3P0oCJki6UdE9ELJB0UNJAvybUD4HvkzTnuM+HOl8beLYnaSzutRGR5Y60SyRdYftNjf04tdT2Q+2OVJsRSSMRcexMa73Ggh9Y/RD4q5LOtT2v86LGSklPtDxTz2xbYz/L7YyIu9qepy4RcXtEDEXEXI39v3o+Iq5peaxaRMTbkvbant/50jJJA/2i6Hj3JqtdRIzavkHSs5ImSLo/Ira3PFYdlki6VtLfbW/tfO1nEfFUizOhuxslre0cbPZIur7leXrS+q/JADSnH07RATSEwIHECBxIjMCBxAgcSIzAgcQIHEiMwIHE/guVLZ6gzFw6rgAAAABJRU5ErkJggg==\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "adv = attack.generate(X[:14],np.array([6,6,7,7,8,8,9,9,1,1,2,2,3,3]))\n",
    "print(clf.predict(adv))\n",
    "plt.imshow(adv[0].reshape(8,8))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Finally, the attack has an offset parameter which specifies how close the new value of the feature is compared to the learned threshold of the tree. The default value is very small (0.001), however the value can be set larger when desired. Setting it to a very large value might however yield adversarial examples outside the range or normal features!"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[5 4 4 4 5 4 1 2 4 4 5 4 4 4]\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "<matplotlib.colorbar.Colorbar at 0x7f946ca739e8>"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    },
    {
     "data": {
      "image/png": "i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P897gXcOOZ6YYejTGiIi6hqFLmFERC1JWBFRjCSsiChGElZEFCMJKyKKkYQVEcVIwoqIYvwf6P8bJJGfgB8AAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 2 Axes>"
      ]
     },
     "metadata": {
      "needs_background": "light"
     },
     "output_type": "display_data"
    }
   ],
   "source": [
    "attack = DecisionTreeAttack(clf_art,offset=20.0)\n",
    "adv = attack.generate(X[:14])\n",
    "print(clf.predict(adv))\n",
    "plt.imshow(adv[0].reshape(8,8))\n",
    "plt.colorbar()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
